<?php
class ControllerVoucherReport extends Controller
{
	private $error = array();
	
	public function index()
	{
		$this->id="content";
		$this->template="voucher/paymentvoucher.tpl";
		$this->render();
	}
	
	
	public function purchase()
	{
		$this->load->model("core/user");
		$this->load->model("common/control");
		$this->load->model("category/stock");
		$this->load->model("voucher/order");
		$this->load->model("voucher/orderdetail");
		
		$orderid = $this->request->get['orderid'];
		
		$this->data['order'] = $this->model_voucher_order->getItem($orderid);
		
		$this->data['error'] = false;
		if($this->data['order']['orderid'] == "")
		{
			$this->data['error'] = true;	
		}
		else
		{
			$this->data['employee'] = $this->model_core_user->getItem($this->data['order']['employeeid']);
			$this->data['partner'] = $this->model_core_user->getItem($this->data['order']['partnerid']);
			
			$this->data['order']['orderdate'] = $this->date->formatMySQLDate($this->data['order']['orderdate']);
			$this->data['order']['subtotal'] = $this->string->numberFormate($this->data['order']['subtotal']);
			$this->data['order']['taxamount'] = $this->string->numberFormate($this->data['order']['taxamount']);
			$this->data['order']['discountamount'] = $this->string->numberFormate($this->data['order']['discountamount']);
			$this->data['order']['grandtotal'] = $this->string->numberFormate($this->data['order']['grandtotal']);
			
			
			$this->data['orderdetails'] = array();
			$this->data['orderdetails'] = $this->model_voucher_orderdetail->getList(" AND orderid = '".$orderid."'");
			for($i=0; $i<count($this->data['orderdetails']);$i++)
			{
				$this->data['orderdetails'][$i]['qty'] = $this->string->numberFormate($this->data['orderdetails'][$i]['qty']);
				$this->data['orderdetails'][$i]['netprice'] = $this->string->numberFormate($this->data['orderdetails'][$i]['netprice']);
				$this->data['orderdetails'][$i]['saleprice'] = $this->string->numberFormate($this->data['orderdetails'][$i]['saleprice']);
				$this->data['orderdetails'][$i]['subtotal'] = $this->string->numberFormate($this->data['orderdetails'][$i]['subtotal']);
				$this->data['orderdetails'][$i]['grandtotal'] = $this->string->numberFormate($this->data['orderdetails'][$i]['grandtotal']);
			}
		}
		
		
		$this->id="content";
		$this->template="voucher/report_purchase.tpl";
		$this->render();
		
	}
	
	public function saleorder()
	{
		$this->load->model("core/user");
		$this->load->model("common/control");
		$this->load->model("category/stock");
		$this->load->model("voucher/order");
		$this->load->model("voucher/orderdetail");
		
		$orderid = $this->request->get['orderid'];
		
		$this->data['order'] = $this->model_voucher_order->getItem($orderid);
		
		$this->data['error'] = false;
		if($this->data['order']['orderid'] == "")
		{
			$this->data['error'] = true;	
		}
		else
		{
			$this->data['employee'] = $this->model_core_user->getItem($this->data['order']['employeeid']);
			$this->data['partner'] = $this->model_core_user->getItem($this->data['order']['partnerid']);
			
			$this->data['order']['orderdate'] = $this->date->formatMySQLDate($this->data['order']['orderdate']);
			$this->data['order']['subtotal'] = $this->string->numberFormate($this->data['order']['subtotal']);
			$this->data['order']['taxamount'] = $this->string->numberFormate($this->data['order']['taxamount']);
			$this->data['order']['discountamount'] = $this->string->numberFormate($this->data['order']['discountamount']);
			$this->data['order']['grandtotal'] = $this->string->numberFormate($this->data['order']['grandtotal']);
			
			
			$this->data['orderdetails'] = array();
			$this->data['orderdetails'] = $this->model_voucher_orderdetail->getList(" AND orderid = '".$orderid."'");
			for($i=0; $i<count($this->data['orderdetails']);$i++)
			{
				$this->data['orderdetails'][$i]['qty'] = $this->string->numberFormate($this->data['orderdetails'][$i]['qty']);
				$this->data['orderdetails'][$i]['netprice'] = $this->string->numberFormate($this->data['orderdetails'][$i]['netprice']);
				$this->data['orderdetails'][$i]['saleprice'] = $this->string->numberFormate($this->data['orderdetails'][$i]['saleprice']);
				$this->data['orderdetails'][$i]['subtotal'] = $this->string->numberFormate($this->data['orderdetails'][$i]['subtotal']);
				$this->data['orderdetails'][$i]['grandtotal'] = $this->string->numberFormate($this->data['orderdetails'][$i]['grandtotal']);
			}
		}
		
		
		$this->id="content";
		$this->template="voucher/report_saleorder.tpl";
		$this->render();
		
	}
	
	public function customerreturn()
	{
		$this->load->model("core/user");
		$this->load->model("common/control");
		$this->load->model("category/stock");
		$this->load->model("voucher/order");
		$this->load->model("voucher/orderdetail");
		
		$orderid = $this->request->get['orderid'];
		
		$this->data['order'] = $this->model_voucher_order->getItem($orderid);
		
		$this->data['error'] = false;
		if($this->data['order']['orderid'] == "")
		{
			$this->data['error'] = true;	
		}
		else
		{
			$this->data['employee'] = $this->model_core_user->getItem($this->data['order']['employeeid']);
			$this->data['partner'] = $this->model_core_user->getItem($this->data['order']['partnerid']);
			
			$this->data['order']['orderdate'] = $this->date->formatMySQLDate($this->data['order']['orderdate']);
			$this->data['order']['subtotal'] = $this->string->numberFormate($this->data['order']['subtotal']);
			$this->data['order']['taxamount'] = $this->string->numberFormate($this->data['order']['taxamount']);
			$this->data['order']['discountamount'] = $this->string->numberFormate($this->data['order']['discountamount']);
			$this->data['order']['grandtotal'] = $this->string->numberFormate($this->data['order']['grandtotal']);
			
			
			$this->data['orderdetails'] = array();
			$this->data['orderdetails'] = $this->model_voucher_orderdetail->getList(" AND orderid = '".$orderid."'");
			for($i=0; $i<count($this->data['orderdetails']);$i++)
			{
				$this->data['orderdetails'][$i]['qty'] = $this->string->numberFormate($this->data['orderdetails'][$i]['qty']);
				$this->data['orderdetails'][$i]['netprice'] = $this->string->numberFormate($this->data['orderdetails'][$i]['netprice']);
				$this->data['orderdetails'][$i]['saleprice'] = $this->string->numberFormate($this->data['orderdetails'][$i]['saleprice']);
				$this->data['orderdetails'][$i]['subtotal'] = $this->string->numberFormate($this->data['orderdetails'][$i]['subtotal']);
				$this->data['orderdetails'][$i]['grandtotal'] = $this->string->numberFormate($this->data['orderdetails'][$i]['grandtotal']);
			}
		}
		
		
		$this->id="content";
		$this->template="voucher/report_customerreturn.tpl";
		$this->render();
		
	}
	
	public function returnsupplier()
	{
		$this->load->model("core/user");
		$this->load->model("common/control");
		$this->load->model("category/stock");
		$this->load->model("voucher/order");
		$this->load->model("voucher/orderdetail");
		
		$orderid = $this->request->get['orderid'];
		
		$this->data['order'] = $this->model_voucher_order->getItem($orderid);
		
		$this->data['error'] = false;
		if($this->data['order']['orderid'] == "")
		{
			$this->data['error'] = true;	
		}
		else
		{
			$this->data['employee'] = $this->model_core_user->getItem($this->data['order']['employeeid']);
			$this->data['partner'] = $this->model_core_user->getItem($this->data['order']['partnerid']);
			
			$this->data['order']['orderdate'] = $this->date->formatMySQLDate($this->data['order']['orderdate']);
			$this->data['order']['subtotal'] = $this->string->numberFormate($this->data['order']['subtotal']);
			$this->data['order']['taxamount'] = $this->string->numberFormate($this->data['order']['taxamount']);
			$this->data['order']['discountamount'] = $this->string->numberFormate($this->data['order']['discountamount']);
			$this->data['order']['grandtotal'] = $this->string->numberFormate($this->data['order']['grandtotal']);
			
			
			$this->data['orderdetails'] = array();
			$this->data['orderdetails'] = $this->model_voucher_orderdetail->getList(" AND orderid = '".$orderid."'");
			for($i=0; $i<count($this->data['orderdetails']);$i++)
			{
				$this->data['orderdetails'][$i]['qty'] = $this->string->numberFormate($this->data['orderdetails'][$i]['qty']);
				$this->data['orderdetails'][$i]['netprice'] = $this->string->numberFormate($this->data['orderdetails'][$i]['netprice']);
				$this->data['orderdetails'][$i]['saleprice'] = $this->string->numberFormate($this->data['orderdetails'][$i]['saleprice']);
				$this->data['orderdetails'][$i]['subtotal'] = $this->string->numberFormate($this->data['orderdetails'][$i]['subtotal']);
				$this->data['orderdetails'][$i]['grandtotal'] = $this->string->numberFormate($this->data['orderdetails'][$i]['grandtotal']);
			}
		}
		
		
		$this->id="content";
		$this->template="voucher/report_returnsupplier.tpl";
		$this->render();
		
	}
	
	public function voucher()
	{
		$this->load->model("core/user");
		$this->load->model("voucher/voucher");
		
		$voucherid = $this->request->get['voucherid'];
		
		$this->data['voucher'] = $this->model_voucher_voucher->getItem($voucherid);
		
		$this->data['error'] = false;
		if($this->data['voucher']['voucherid'] == "")
		{
			$this->data['error'] = true;	
		}
		else
		{
			$this->data['employee'] = $this->model_core_user->getItem($this->data['voucher']['employeeid']);
			$this->data['partner'] = $this->model_core_user->getItem($this->data['voucher']['partnerid']);
			
			if($this->data['voucher']['vouchertype'] == "EXPENSE")
			{
				$this->data['voucher']['title'] = "PAYMENT VOUCHER";
				$this->data['voucher']['vendor'] = "Receiver";
			}
			else
			{
				$this->data['voucher']['title'] = "INCOME VOUCHER";
				$this->data['voucher']['vendor'] = "Sender";
			}
			
			$this->data['voucher']['voucherdate'] = $this->date->formatMySQLDate($this->data['voucher']['voucherdate']);
			$this->data['voucher']['totalpaid'] = $this->string->numberFormate($this->data['voucher']['totalpaid']);
		}
		
		
		$this->id="content";
		$this->template="voucher/paymentvoucher.tpl";
		$this->render();
		
	}

}
?>